home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 307.adf / FileIO / FileIO.h < prev    next >
C/C++ Source or Header  |  1990-01-13  |  11KB  |  259 lines

  1. #ifndef FILEIO_H
  2. #define FILEIO_H
  3.  
  4. /* *** fileio.h *************************************************************
  5.  *
  6.  * Amiga Programmers' Suite  --  File IO Include File
  7.  *     from Book 1 of the Amiga Programmers' Suite by RJ Mical
  8.  *
  9.  * Copyright (C) 1986, =Robert J. Mical=
  10.  * All Rights Reserved.
  11.  *
  12.  * Created for Amiga developers.
  13.  * Any or all of this code can be used in any program as long as this
  14.  * entire notice is retained, ok?  Thanks.
  15.  *
  16.  * The Amiga Programmer's Suite Book 1 is copyrighted but freely distributable.
  17.  * All copyright notices and all file headers must be retained intact.
  18.  * The Amiga Programmer's Suite Book 1 may be compiled and assembled, and the 
  19.  * resultant object code may be included in any software product.  However, no 
  20.  * portion of the source listings or documentation of the Amiga Programmer's 
  21.  * Suite Book 1 may be distributed or sold for profit or in a for-profit 
  22.  * product without the written authorization of the author, RJ Mical.
  23.  *
  24.  * HISTORY      NAME            DESCRIPTION
  25.  * -----------  --------------  --------------------------------------------
  26.  * 20 Oct 87    - RJ            Added RENAME_RAMDISK to fix what seems to 
  27.  *                              be a bug in AmigaDOS.
  28.  * 27 Sep 87    RJ              Removed reference to alerts.h, brought 
  29.  *                              declarations into this file
  30.  * 12 Aug 86    RJ              Prepare (clean house) for release
  31.  * 14 Feb 86    =RJ Mical=      Created this file.
  32.  
  33.  From Sept 87 to Dec 89, the original code was rewritten entirely in assembly,
  34.  converted to a disk-based library, and numerous features were added such as:
  35.     1). Filename pattern matching
  36.     2). Support for applications without a window, including BASIC programs
  37.     3). Various string manipulation routines added to replace original
  38.         code.
  39.     4). Improved and debugged error handling and error returns, including
  40.         a better method of recovering from illegal/non-existant path names
  41.     5). Ability to add custom routines in a logical manner
  42.     6). Returns information about the selected file such as whether it exists,
  43.         and what its size is.
  44.     7). Returns free disk space on the selected disk
  45.     8). Automatic handling of filename selection when the requester can't
  46.         open.
  47.     9). Routines for displaying text in the title bar, and getting user input
  48.         via the window title bar.
  49.    10). Improved method of maintaining mounted device and volume names.
  50.    11). A function to parse filenames from AmigaDOS as passed into a program's
  51.         main() function. 
  52.    12). Improved graphic representation for the requester, including
  53.         larger display for filenames and repeat auto-scroll arrows.
  54.    13). Faster text rendering and directory list construction.
  55.    14). Ability to choose the disk name from a list of mounted devices using
  56.         the mouse.
  57.    15). Ability to display custom lists instead of filenames, with all of the
  58.         display features of the requester.
  59.    16). Ability to select multiple filenames.
  60.    17). C, assembly, and Basic examples with support files (INCLUDES).
  61.    18). Smaller size than the original code.
  62.  
  63.    The current version of the library is 1.5 and was created by the programmers
  64. at dissidents. The library is such a significant departure from the original
  65. code that virtually every line of code differs from the original. It really is
  66. a different piece of code than R.J.s, but since he started the ball rolling...
  67.  
  68.  * *********************************************************************** */
  69.  
  70.  
  71. #define MAX_NAME_LENGTH 30
  72. #define MAX_DRAWER_LENGTH 132
  73. #define SetFlag(v,f)      ((v)|=(f))
  74. #define ClearFlag(v,f)    ((v)&=~(f))
  75. #define ToggleFlag(v,f)   ((v)^=(f))
  76. #define FlagIsSet(v,f)    ((BOOL)(((v)&(f))!=0))
  77.  
  78. struct HandlerBlock {
  79.    APTR  StartUpCode;
  80.    APTR  DiskInsertedCode;
  81.    APTR  GadgetCode;
  82.    APTR  KeyCode;
  83.    APTR  MouseMoveCode;
  84.    };
  85.  
  86. /* === FileIO Structure ========================================== */
  87.  
  88. struct FileIO {
  89.    USHORT Flags;
  90.    /* After a successful call to DoFileIO(), these fields will have
  91.     * the names selected by the user.  You should never have to initialize
  92.     * these fields, only read from them, though initializing them won't hurt.
  93.     */
  94.    UBYTE FileName[MAX_NAME_LENGTH];
  95.    UBYTE Drawer[MAX_DRAWER_LENGTH];
  96.    UBYTE Disk[MAX_NAME_LENGTH];
  97.  
  98.    /* If a Lock on a disk/dir was obtained, it can be found here. */
  99.    struct DOSLock *Lock;
  100.  
  101.    USHORT NameCount;
  102.    USHORT NameStart;
  103.    SHORT  CurrPick;
  104.    struct Remember *FileList;
  105.  
  106.    UBYTE *FileIOText;             /* for SPECIAL_REQ */
  107.    APTR FileIORoutine;            /* for SPECIAL_REQ */
  108.  
  109.    SHORT MatchType;  /* DiskObject Type */
  110.    UBYTE *ToolTypes;
  111.  
  112.    UBYTE *Extension;
  113.    USHORT ExtSize; /* Don't count the terminating NULL */
  114.  
  115.    struct HandlerBlock *Custom;
  116.  
  117.    USHORT X;
  118.    USHORT Y;
  119.  
  120.    ULONG  FreeBytes;
  121.    ULONG  FileSize;
  122.  
  123.    UBYTE  *Title;
  124.    UBYTE  *Buffer;
  125.  
  126.    APTR   RawCode;
  127.    struct DOSLock  *OriginalLock;
  128.    BYTE   Errno;
  129.    UBYTE  DrawMode;
  130.    UBYTE  PenA;
  131.    UBYTE  PenB;
  132.    };
  133.  
  134. /* === User FileIO Flag Definitions === */
  135. #define NO_CARE_REDRAW     0x0001  /* Clear if reconstructing display */
  136. #define USE_DEVICE_NAMES   0x0002  /* Set for device instead of volume names */
  137. #define EXTENSION_MATCH    0x0004  /* Only display those that end with
  138.                                       a specified string */
  139. #define DOUBLECLICK_OFF    0x0008  /* Inhibit double-clicking if set */
  140. #define WBENCH_MATCH       0x0010  /* If set check .info files only */
  141. #define MATCH_OBJECTTYPE   0x0020  /* If set with .info also check ObjectType */
  142. #define MULTIPLE_FILES     0x0040  /* If set with .info also check ToolType */
  143. #define INFO_SUPPRESS      0x0080  /* No info files listed */
  144. #define CUSTOM_HANDLERS    0x0200  /* Implement custom handlers */
  145. #define NO_ALPHA           0x1000  /* No alphabetize filenames or lists */
  146. #define SHOW_DISK_NAMES    0x4000  /* Show disk names instead of filenames */
  147. #define SPECIAL_REQ        0x8000  /* For displaying lists of strings */
  148.  
  149. /* === System FileIO Flag Definitions === */
  150. #define ALLOCATED_FILEIO   0x0100  /* Not a pre-initialized FileIO struct */
  151. #define WINDOW_OPENED      0x0400  /* DoFileIOWindow() was called */
  152. #define TITLE_CHANGED      0x0800  /* SetTitle() called without ResetTitle() */
  153.  
  154. #define DISK_HAS_CHANGED   0x2000  /* Disk changed during DoFileIO() */
  155.  
  156. /*  FileRequester GadgetIDs - Do not use these IDs for your own gadgets */
  157. #define FILEIO_CANCEL      0x7FA0
  158. #define FILEIO_OK          0x7FA1
  159. #define FILEIO_NAMETEXT    0x7FA2
  160. #define FILEIO_DRAWERTEXT  0x7FA3
  161. #define FILEIO_DISKTEXT    0x7FA4
  162. #define FILEIO_SELECTNAME  0x7FA5
  163. #define FILEIO_UPGADGET    0x7FA6
  164. #define FILEIO_DOWNGADGET  0x7FA7
  165. #define FILEIO_PROPGADGET  0x7FA8
  166. #define FILEIO_NEXTDISK    0x7FA9
  167. #define FILEIO_BACKDROP    0x7FAA
  168.  
  169. #define NAME_ENTRY_COUNT   7   /* These many names in the SelectName box */
  170.  
  171. #define REQTITLE_HEIGHT    8
  172.  
  173. #define REQ_LEFT          8
  174. #define REQ_TOP           15
  175. #define REQ_WIDTH         286
  176. #define REQ_HEIGHT        (110 + REQTITLE_HEIGHT)
  177. #define REQ_LINEHEIGHT    8
  178.  
  179. #define SELECTNAMES_LEFT    8
  180. #define SELECTNAMES_TOP     (15 + REQTITLE_HEIGHT)
  181. #define SELECTNAMES_WIDTH   122
  182. #define SELECTNAMES_HEIGHT  60
  183.  
  184.  
  185.  /* ======= ERRNO numbers returned in FileIO error field ========= */
  186.  
  187. #define ERR_MANUAL  1   /* the path was entered manually via the title bar
  188.                            with no errors or cancellation. */
  189. #define ERR_SUCCESS 0   /* everything went OK */
  190. #define ERR_CANCEL  -1  /* the filename procedure was CANCELED by the user */
  191. #define ERR_INUSE   -2  /* for SPECIAL_REQ, the requester is in use by another task */
  192. #define ERR_APPGADG -3  /* the requester was CANCELED by an application gadget
  193.                            (via an installed CUSTOM gadget handler returning TRUE) */
  194. #define ERR_WINDOW  -4  /* the window couldn't open (in DoFileIOWindow()) */
  195.  
  196. /* === AutoFileMessage() Numbers ================================= */
  197. #define ALERT_OUTOFMEM            0
  198. #define ALERT_BAD_DIRECTORY       1
  199. #define READ_WRITE_ERROR          2 /* Error in reading or writing file */
  200.  /* The next 3 display "YES" and "NO" prompts,
  201.     returning d0=1 for yes, 0 for no */
  202. #define FILE_EXISTS               3 /* File already exists. Overwrite? */
  203. #define SAVE_CHANGES              4 /* Changes have been made. Save them? */
  204. #define REALLY_QUIT               5 /* Do you really want to quit? */
  205.  
  206. /* ====================== Entry Structure ====================== */
  207. /* Don't use sizeof on these structures. The library makes them for you when
  208.    you call AddEntry. The 3rd field of the Entry structure is a variable length
  209.    string. This structure has been defined simply so that you can get access to
  210.    the EntryID EntryFlags, and EntryString. This structure is used by
  211.    SPECIAL_REQ, and also for the list of filenames. For filenames, each has a
  212.    FileEntry structure. Its EntryID is the filesize. Bit #7 of the EntryFlags
  213.    is set if the filename was selected by the user. The EntryString is the
  214.    NULL-terminated filename (separated from its dir). When the SPECIAL_REQ
  215.    flag is set, the Entry's EntryID is your passed ID to AddEntry().
  216.    All the FileEntry structures are linked together, and the FileIO's
  217.    FileList field points to the first FileEntry in the list. */
  218.  
  219. struct Entry {
  220.    LONG  EntryID;
  221.    UBYTE EntryFlags;
  222.    UBYTE EntryString[1]; /* size is actually length of null-terminated string */
  223.    };
  224.  
  225. struct FileEntry {
  226.     struct FileEntry  *nextEntry;
  227.    ULONG  EntrySize;
  228.    struct Entry     *filePart;
  229.    };
  230.  
  231. /* === Requester Library Function Declarations ===================== */
  232.  
  233. extern struct FileIO *GetFileIO();
  234. extern UBYTE  *DoFileIO();
  235. extern UBYTE  *DoFileIOWindow();  /* address = DoFileIOWindow(myFileIO, myScreen);
  236.                                   If myScreen is NULL, then use WB screen */
  237. extern BOOL   AutoFileMessage(); /* result = AutoFileMessage(3L, myWindow); */
  238. extern BOOL   AutoMessage(), AutoMessageLen(), AutoPrompt3();
  239. extern void   ReleaseFileIO();
  240. extern void   SetWaitPointer();  /* SetWaitPointer( myWindow ); */
  241. extern void   ResetBuffer();     /* ResetBuffer( StringInfo, nullFlag ); resets the
  242.                              cursor back to the first char in the stringinfo's
  243.                              buffer. If nullFlag is TRUE, then NULLS the buffer
  244.                              as well. */
  245. extern UBYTE  *ParseString();
  246. extern UBYTE  *TypeFilename();
  247. extern UBYTE  *PromptUserEntry(), *UserEntry();
  248. extern void   SetTitle(), ResetTitle();
  249. extern UWORD  GetRawkey(), DecodeRawkey();
  250.  
  251. extern VOID  SetFileIOHandlers();
  252.  
  253. extern WORD   NewEntryList(), AddEntry(), IsEntryThere();
  254. extern struct FileEntry  *RetrieveEntry();
  255. extern void   ClearEntries();
  256.  
  257. #endif /* of FILEIO_H */
  258.  
  259.